<template>
  <div>
    <div v-for="carItem in carsList" style="position: relative;">
			<item class="cars-item clearfix"  style="margin: 0;">
				<!-- <router-link :to="'/car/'+carItem.carId"> -->
					<div class="cars-img">
						<span v-if="carItem.carAuthState==10">
							<img src="static/images/png/mark.png" alt="" />
						</span>
						<img :src="imgUrl + carItem.carImageUrl + '.r_120xh_90'" onerror="javascript:this.src='static/images/default.png';">
						
						<div class="car-state" v-if="carItem.carBargainPriceState"><em style="background: #FF6816;">特卖</em></div>
						<div class="car-state" v-if="carItem.carOrderState==1"><em>已预定</em></div>
					</div>
					
					<div class="cars-info">
						<h2 class="cars-title">{{carItem.carTitle}}</h2>
						<p class="cars-mile">{{carItem.carMileage}}万公里 / 
							<span v-if="carItem.carLicenceState == 1">{{carItem.carLicenceDate | filterDateForYear}}</span>
              <span v-else >{{carItem.carLicenceState | filterCarLicenceStatus}}</span>
						</p>
						<p class="cars-mile">{{carItem.shop.shopName}}</p>
						<p class="cars-status" style="color:#777">车架号：{{carItem.carVin}}</p>
					</div>
				<!-- </router-link>				 -->
				<div class="caroptions-testing" :data="carItem.carDetectState" >
					<span @click="testingFnChange(carItem)" v-if="carItem.carDetectState == 500 && carItem.carStockState != 40" >检测</span>
					<small v-else>{{carItem.carDetectState | filterCarDetectState}}</small>
					<em>{{carItem.carCreateTime | filterDateForDayTime}}</em>
				</div>
			</item>
		</div>
  </div>
</template>
<script>
import { bus } from 'bus.js'
export default {
	
  data() {
    return {
			imgUrl: window.imgUrl,
		}
  },
  methods: {
		testingFnChange (item) {
			let options = {
				effect: 'scale',
				title: '',
				buttons: [
					{text: '通过'},
					{text: '不通过'},
				],
				showClose:true,
			}
			let popup = $popup.fromTemplate('<p class="popup-text">初检是否通过</p>', options)
			popup.show().then(res => {
				if (res===1) {
					let options2 = {
						effect: 'scale',
						title: '',
						buttons: [
							{text: '确定'},
							{text: '取消'}							
						],
						showClose:true,
						abc:1,
					}
					let popup2Params = ''
					bus.$off('globalPopupChange')
					bus.$on('globalPopupChange', (val) => {
						popup2Params = val[0]
					})
					let popup2 = $popup.fromTemplate('<global-popup></global-popup>', options2)
					popup2.show().then(res2 => {
						if (res2 === 0) {
							window.axios
								.get(baseUrl + '/controller/car/updateCarState', {params: {
									carId: item.carId,
									stateKey: 'carDetectState',
									stateValue: 510,
									content: popup2Params,
									userId: sess.get('userSession').userId
								}})
								.then(res => {
									item.carDetectState = 510
									this.errorFn(res, item)
								})
						} else {
							return false
						}
					})
				} else if (res === 0) {
					window.axios
						.get(baseUrl + '/controller/car/updateCarState', {params: {
							carId: item.carId,
							stateKey: 'carDetectState',
							stateValue: 520,
							userId: sess.get('userSession').userId
						}})
						.then(res => {
							item.carDetectState = 520
							this.errorFn(res, item)
						})
				}
			})
		},
		errorFn(res, item) {
			if (res && res.data.code == 1){
				setTimeout(() => {
					$toast.show('修改成功')
				}, 400)
			} else {
				setTimeout(() => {
					$toast.show('修改失败,请重新尝试修改')
				}, 400)
			}
		}
	},
  created() {
		
	},
  props: [
    'carsList'
	],
	watch: {
		"abc" () {
			console.log(this.abc)
		}
	}	
}
</script>
<style>
	.popup-buttons .button.button-block.button-light:nth-child(1){ color: #0C80FF;}
	.popup-buttons .button.button-block.button-light:nth-child(2){ color: #FF0808;}
</style>


